package com.demo.dao;

import com.demo.common.model.Airroute;
import com.demo.common.model.Buyrecord;
import com.jfinal.kit.Kv;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.SqlPara;

import java.util.List;

public class BuyrecordDao {

    private Buyrecord dao = new Buyrecord().dao();

    public Page<Buyrecord> paginate(int pageNumber, int pageSize) {
        return dao.paginate(pageNumber, pageSize, "select *", "from buyrecord order by id asc");
    }

    public Page<Buyrecord> paginate(int pageNumber, int pageSize, Kv cond) {
        SqlPara sqlPara = dao.getSqlPara("searchBuyrecord", cond);
        return dao.paginate(pageNumber, pageSize, sqlPara);
    }

    public Buyrecord findById(int id) {
        return dao.findById(id);
    }

    public void deleteById(int id) {
        dao.deleteById(id);
    }

    public List<Buyrecord> findAll() {
        return dao.findAll();
    }

    public int findTicketNumByTimeNo(String timeno) {
        String sql = "select IFNULL(sum(ticketnum),0) ticketnums from buyrecord where flighttimeno='" + timeno + "'";
        return Db.queryInt(sql);
    }
}
